package com.wmada.spring.caching;

import org.springframework.cache.annotation.CachingConfigurerSupport;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.interceptor.KeyGenerator;
import org.springframework.context.annotation.Configuration;

import java.lang.reflect.Method;

/**
 * @author will.ma
 * @date 2020-9-28
 */
@Configuration
@EnableCaching
public class RedisConfig extends CachingConfigurerSupport {
    @Override
    public KeyGenerator keyGenerator() {
        return (target, method, params) -> {
            StringBuilder sb = new StringBuilder();
            sb.append(target.getClass().getName()).append('>');
            sb.append(method.getName()).append(':');
            for (Object obj : params) {
                sb.append(obj.toString()).append('!');
            }
            return sb.toString();
        };
    }
}
